package com.lago.proxy;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author yuhe
 * @version 1.0
 * @date 2020/11/19 10:58
 */
public class JDKDyamicProxy implements InvocationHandler {
    //声明被代理的对象
    private  Person person;
    //构造函数
    public JDKDyamicProxy(Person person) {
        this.person = person;
    }
    //获取代理对象
    public Object getTarget(){
        Object o = Proxy.newProxyInstance(person.getClass().getClassLoader(), person.getClass().getInterfaces(), this);
        return o;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("对原方法进行前置增强");
       //原方法执行
        Object invoke = method.invoke(person, args);
        System.out.println("对原方法进行后制增强");
        return null;
    }
}
